home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / PERMUTE.TST / TSTPMTCH.C < prev   
C/C++ Source or Header  |  1996-02-29  |  2KB  |  66 lines

  1. /* ============ */
  2. /* tstpmtch.c    */
  3. /* ============ */
  4. /* ==================================================================== */
  5. /*             Main Program to Test CalcPermuteChiSq        */
  6. /* ==================================================================== */
  7.  
  8. #include <time.h>
  9. #include <mconf.h>
  10. #include <anlzpmtn.c>
  11. void
  12. main()
  13. {
  14.     double  ChiSqProb;
  15.  
  16.     PRMUT_DATA_STRU PermuteData;
  17.  
  18.     int     CellExpect, NumElements;
  19.     while (main)
  20.     {
  21.     do
  22.     {
  23.         GetInt("Enter No. Elements Per Permutation [3-7]: ",
  24.         &NumElements);
  25.     }
  26.     while (NumElements < 3 || NumElements > 7);
  27.  
  28.     PermuteData.NumElements = NumElements;
  29.  
  30.     PermuteData.NumCategories = (int) fac(PermuteData.NumElements);
  31.  
  32.     do
  33.     {
  34.         GetInt("Enter Expectation for Each Category [>= 5]: ",
  35.         &CellExpect);
  36.     }
  37.     while (CellExpect < 5);
  38.  
  39.     PermuteData.CellExpectation = CellExpect;
  40.     PermuteData.RandFun = rand;
  41.  
  42.     PermuteData.NumObs = (UINT) PermuteData.CellExpectation *
  43.         PermuteData.NumCategories;
  44.  
  45.     srand(1);
  46.     srand((unsigned) time(NULL));
  47.  
  48.     CalcPermuteChiSq(&PermuteData);
  49.     ChiSqProb = 100.0 *
  50.         chdtr(PermuteData.NumCategories - 1,
  51.           PermuteData.PrmutChiSqStat);
  52.  
  53.     printf("%6d  Number of Elements Per Permutation\n", NumElements);
  54.     printf("%6d  Categories in This Test\n", PermuteData.NumCategories);
  55.     printf("%6d  Expected Events Per Category\n", CellExpect);
  56.     printf("%6u  Observations (Permutations) Will be Analyzed\n",
  57.             PermuteData.NumObs);
  58.     printf("%6lu  Random Numbers Will Be Generated\n\n",
  59.             (ULONG) PermuteData.NumObs * NumElements);
  60.  
  61.     printf("Chi-Square Statistic = %f\n", PermuteData.PrmutChiSqStat);
  62.     printf("Chi-Square Probability for %d Degrees of Freedom = %f\n",
  63.             PermuteData.NumCategories - 1, ChiSqProb);
  64.     }
  65. }
  66.